package sto.orz.rptp.service;

import java.util.List;

import net.sf.json.JSONObject;

import sto.orz.rptp.dao.DefinitionDao;
import sto.orz.rptp.model.*;
import sto.orz.service.impl.BaseManager;

// 暂时没有加入 Dao 层,将在恰当的时机重构引入
public class DefinitionManager extends BaseManager {
	/** 新建报表时,默认的报表方案名称 */
	public static final String UNTITLED = "新建报表方案";
	DefinitionDao dao;

	public Definition createNewReportDefinition() {
		return this.createNewReportDefinition(UNTITLED);
	}

	public Definition createNewReportDefinition(String name) {
		name = (name != null) ? name : UNTITLED;
		Definition definition = new Definition();
		definition.setName(name);
		dao.saveDefinition(definition);
		return definition;
	}

	public List getAll() {
		return dao.getDefinitionIndex();
	}

	public Definition getDefinition(String definitionId) {
		return dao.getDefinition(definitionId);
	}

	public void removeDefinition(String definitionId) {
		dao.removeDefinition(definitionId);
	}

	public void saveDefinition(final Definition definition) {
		dao.saveDefinition(definition);
	}

	public void saveObject(final Object object) {
		dao.saveObject(object);
	}

	public void setRptdDao(DefinitionDao dao) {
		this.dao = dao;
	}

	public String toJson(String definitionId) {
//		Definition definition = (Definition) getHibernateTemplate().get(
//				Definition.class, definitionId);
//		java.util.Map out = new java.util.HashMap();
//		out.put("id", definition.getId());
//		out.put("id", definition.getName());
//		
//		java.util.Map attr = new java.util.HashMap();
//		out.put("id", definition.getAttributes());
//		out.put("id", definition.getId());
//		out.put("id", definition.getId());
//		out.put("id", definition.getId());
//		JSONObject j = JSONObject.fromObject(out);
		return null;
	}
}
